package config;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import javax.sql.DataSource;

public class DatabaseConnectionPool {

    public static DataSource createConnectionPool(String url, String username, String password) {
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl(url);
        config.setUsername(username);
        config.setPassword(password);
        config.addDataSourceProperty("cachePrepStmts", "true");
        config.addDataSourceProperty("prepStmtCacheSize", "250");
        config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");

        // 可以设置更多的配置项，例如连接超时时间、最大连接数等
        // config.setConnectionTimeout(5000);
         config.setMaximumPoolSize(5);

        // 根据配置创建HikariDataSource实例
        return new HikariDataSource(config);
    }

}